package com.hq.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hq.pojo.Conver;
import com.hq.service.ConverService;
import com.hq.service.impl.ConverImpl;
import com.hq.utils.JSONObjectUtil;

/**
 * Servlet implementation class InsertConverServlet
 */
@WebServlet("/InsertConverServlet")
public class InsertConverServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter print = response.getWriter();
		String circleId = request.getParameter("cid");
		String accountId = request.getParameter("aid");
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		String image1 = request.getParameter("image1");
		String image2 = request.getParameter("image2");
		String image3 = request.getParameter("image3");
		ConverService service = new ConverImpl();
		int i = service.insertConver(getCovner(Integer.valueOf(circleId), Integer.valueOf(accountId), title, content, image1, image2, image3));
		print.print(JSONObjectUtil.createInsertConverResult(i));
		print.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	private Conver getCovner(int circleId,int accountId,String title,String content,String image1,String image2,String image3) {
		Conver conver = new Conver();
		conver.setCircle_id(circleId);
		conver.setAccount_id(accountId);
		conver.setConver_title(title);
		conver.setConver_content(content);
		conver.setConver_image1(image1);
		conver.setConver_image2(image2);
		conver.setConver_image3(image3);
		return conver;
	}

}
